from django.http import HttpResponse
from django.shortcuts import render, get_object_or_404

# Create your views here.
from cat.models import Cat


def index(request):

    return  HttpResponse('hello,word')
    # cats = Cat.objects.all()
    # context = {
    #     'cats_list':cats
    # }
    # return render(request,'cat/index.html',context)

def detail(request,id):
    cat = get_object_or_404(Cat,id=id)
    return render(request,'cat/detail.html',{'cat':cat})

def add(request):
    if request.method == 'GET':
        return render(request,'cat/add.html',{})
    elif request.method == 'POST':
        name = request.POST['name']
        age = request.POST['age']
        sex = request.POST['sex']
        cat = Cat(name=name,age=age,sex=sex)
        cat.save()
        cat_list = Cat.objects.all()
        context = {
            'cats_list':cat_list
        }
        return render(request,'cat/index.html',context)
def hello_country(request,country_name):

    return HttpResponse(f'hello,{country_name}')

def hi(request,country_name,name):

    return HttpResponse(f'hello,{country_name}--{name}')

def hello2(request):

    if request.method == 'GET':
        country_name = request.GET['country_name']
        name = request.GET.get('name')
        return HttpResponse(f'welcome to {country_name},{name}')


